// pages/schoolNav/schoolNav.js
var amapFile = require('../../utils/amap-wx.js');
var sliderWidth = 96;
var markersData = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mapHeight: "800",
    placeName: "",
    hideOrNot: 0,
    activePlaceID: -1,
    markers: [{
      id: 0,
      latitude: 23.306172,
      longitude: 112.96727854,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '公交站',
        display: 'ALWAYS'
      }
    }, {
      id: 1,
      latitude: 23.30073,
      longitude: 112.97368,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '体育馆',
        display: 'ALWAYS'
      }
    }, {
      id: 2,
      latitude: 23.3004968,
      longitude: 112.9733671,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '大川影院',
        display: 'ALWAYS'
      }
    },{
      id: 3,
      latitude: 23.303137,
      longitude: 112.968405,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '游泳馆',
        display: 'ALWAYS'
      }
    },
     {
      id: 4,
      latitude: 23.301329,
      longitude: 112.971891,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '图书馆',
        display: 'ALWAYS'
      }
    }, {
      id: 5,
      latitude: 23.300930,
      longitude: 112.969177,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '大操场',
        display: 'ALWAYS'
      }
    }, {
      id: 6,
      latitude: 23.297087,
      longitude: 112.972889,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '小操场',
        display: 'ALWAYS'
      }
    },{
      id: 7,
      latitude: 23.306000,
      longitude: 112.96767,
      iconPath: "/img/xiaomen.png",
      width: 30,
      height: 32,
      callout: {
        content: '校门',
        display: 'ALWAYS'
      }
    },{
      id: 8,
      latitude: 23.303743,
      longitude: 112.972551,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '行政楼',
        display: 'ALWAYS'
      }
    }, {
      id: 9,
      latitude: 23.303211,
      longitude: 112.97251,
      iconPath: "/img/jiaoxuelou.png",
      width: 30,
      height: 32,
      callout: {
        content: '1号教学楼',
        display: 'ALWAYS'
      }
    }, {
      id: 10,
      latitude: 23.302196,
      longitude: 112.972519,
      iconPath: "/img/jiaoxuelou.png",
      width: 30,
      height: 32,
      callout: {
        content: '2号教学楼',
        display: 'ALWAYS'
      }
    }, {
      id: 11,
      latitude: 23.303172,
      longitude: 112.971264,
      iconPath: "/img/jiaoxuelou.png",
      width: 30,
      height: 32,
      callout: {
        content: '1号实验楼',
        display: 'ALWAYS'
      }
    }, {
      id: 12,
      latitude: 23.302103,
      longitude: 112.971291,
      iconPath: "/img/jiaoxuelou.png",
      width: 30,
      height: 32,
      callout: {
        content: '2号实验楼',
        display: 'ALWAYS'
      }
    },
     {
      id: 13,
      latitude: 23.301309,
      longitude: 112.971226,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '系部楼',
        display: 'ALWAYS'
      }
    },
    {
      id: 14,
      latitude: 23.301201,
      longitude: 112.973077,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '学生活动中心',
        display: 'ALWAYS'
      }
    }, {
      id: 15,
      latitude: 23.302654,
      longitude: 112.971875,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '厚德广场',
        display: 'ALWAYS'
      }
    }, {
      id: 16,
      latitude: 23.305684,
      longitude: 112.968169,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '接待办公室',
        display: 'ALWAYS'
      }
    }, {
      id: 17,
      latitude: 23.305684,
      longitude: 112.96724,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '继续教育学院招生办',
        display: 'ALWAYS'
      }
    }, {
      id: 18,
      latitude: 23.304704,
      longitude: 112.967997,
      iconPath: "/img/xingzheng.png",
      width: 30,
      height: 32,
      callout: {
        content: '国际学术交流中心',
        display: 'ALWAYS'
      }
    }, {
      id: 19,
      latitude: 23.304127,
      longitude: 112.966945,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '商业街',
        display: 'ALWAYS'
      }
    }, {
      id: 20,
      latitude: 23.300866,
      longitude: 112.972508,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '人工湖',
        display: 'ALWAYS'
      }
    }, {
      id: 21,
      latitude: 23.301378,
      longitude: 112.970218,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '大篮球场',
        display: 'ALWAYS'
      }
    }, {
      id: 22,
      latitude: 23.296599,
      longitude: 112.9730989,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '小篮球场',
        display: 'ALWAYS'
      }
    }, {
      id: 23,
      latitude: 23.300472,
      longitude: 112.970250,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '足球场',
        display: 'ALWAYS'
      }
    }, {
      id: 24,
      latitude: 23.299802,
      longitude: 112.968812,
      iconPath: "/img/sports.png",
      width: 30,
      height: 32,
      callout: {
        content: '网球场',
        display: 'ALWAYS'
      }
    },{
      id: 25,
      latitude: 23.302753,
      longitude: 112.973345,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '第一食堂',
        display: 'ALWAYS'
      }
    }, {
      id: 26,
      latitude: 23.301482,
      longitude: 112.975142,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '第二食堂',
        display: 'ALWAYS'
      }
    }, {
      id: 27,
      latitude: 23.298255,
      longitude: 112.97268587,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '第三食堂',
        display: 'ALWAYS'
      }
    }, {
      id: 28,
      latitude: 23.296781,
      longitude: 112.975791,
      iconPath: "/img/shitang.png",
      width: 30,
      height: 32,
      callout: {
        content: '第四食堂',
        display: 'ALWAYS'
      }
    },{
      id: 29,
      latitude: 23.30246,
      longitude: 112.973383,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '1栋',
        display: 'ALWAYS'
      }
    }, {
      id: 30,
      latitude: 23.30223,
      longitude: 112.9734208,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '2栋',
        display: 'ALWAYS'
      }
    }, {
      id: 31,
      latitude: 23.30200944,
      longitude: 112.973426,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '3栋',
        display: 'ALWAYS'
      }
    }, {
      id: 32,
      latitude: 23.30175817,
      longitude: 112.973458,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '4栋',
        display: 'ALWAYS'
      }
    }, {
      id: 33,
      latitude: 23.3015512,
      longitude: 112.973597,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '5栋',
        display: 'ALWAYS'
      }
    }, {
      id: 34,
      latitude: 23.301290,
      longitude: 112.9736568,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '6栋',
        display: 'ALWAYS'
      }
    }, {
      id: 35,
      latitude: 23.3010831,
      longitude: 112.9737963,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '7栋',
        display: 'ALWAYS'
      }
    }, {
      id: 36,
      latitude: 23.302241,
      longitude: 112.9742093,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '8栋',
        display: 'ALWAYS'
      }
    }, {
      id: 37,
      latitude: 23.301999,
      longitude: 112.974311,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '9栋',
        display: 'ALWAYS'
      }
    }, {
      id: 38,
      latitude: 23.301777,
      longitude: 112.974343,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '10栋',
        display: 'ALWAYS'
      }
    }, {
      id: 39,
      latitude: 23.301541,
      longitude: 112.974472,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '11栋',
        display: 'ALWAYS'
      }
    }, {
      id: 40,
      latitude: 23.301324,
      longitude: 112.974477,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '12栋',
        display: 'ALWAYS'
      }
    }, {
      id: 41,
      latitude: 23.301127,
      longitude: 112.974466,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '13栋',
        display: 'ALWAYS'
      }
    }, {
      id: 42,
      latitude: 23.30095,
      longitude: 112.975700,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '14栋',
        display: 'ALWAYS'
      }
    }, {
      id: 43,
      latitude: 23.300693,
      longitude: 112.975706,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '15栋',
        display: 'ALWAYS'
      }
    }, {
      id: 44,
      latitude: 23.300462,
      longitude: 112.975732,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '16栋',
        display: 'ALWAYS'
      }
    }, {
      id: 45,
      latitude: 23.3002160,
      longitude: 112.975759,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '17栋',
        display: 'ALWAYS'
      }
    }, {
      id: 46,
      latitude: 23.300004,
      longitude: 112.975614,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '18栋',
        display: 'ALWAYS'
      }
    }, {
      id: 47,
      latitude: 23.29970858,
      longitude: 112.974391,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '19栋',
        display: 'ALWAYS'
      }
    }, {
      id: 48,
      latitude: 23.299718,
      longitude: 112.975448,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '20栋',
        display: 'ALWAYS'
      }
    }, {
      id: 49,
      latitude: 23.299550,
      longitude: 112.974391,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '21栋',
        display: 'ALWAYS'
      }
    }, {
      id: 50,
      latitude: 23.2995410,
      longitude: 112.9753627,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '22栋',
        display: 'ALWAYS'
      }
    }, {
      id: 51,
      latitude: 23.299294,
      longitude: 112.9743273,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '23栋',
        display: 'ALWAYS'
      }
    }, {
      id: 52,
      latitude: 23.299309,
      longitude: 112.975073,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '24栋',
        display: 'ALWAYS'
      }
    }, {
      id: 53,
      latitude: 23.2990582,
      longitude: 112.9743220,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '25栋',
        display: 'ALWAYS'
      }
    }, {
      id: 54,
      latitude: 23.2988562,
      longitude: 112.9748101,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '26栋',
        display: 'ALWAYS'
      }
    }, {
      id: 55,
      latitude: 23.298831,
      longitude: 112.974316,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '27栋',
        display: 'ALWAYS'
      }
    }, {
      id: 56,
      latitude: 23.298560,
      longitude: 112.9742844,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '28栋',
        display: 'ALWAYS'
      }
    }, {
      id: 57,
      latitude: 23.298393,
      longitude: 112.974252,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '29栋',
        display: 'ALWAYS'
      }
    }, {
      id: 58,
      latitude: 23.2981664,
      longitude: 112.974177,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '30栋',
        display: 'ALWAYS'
      }
    }, {
      id: 59,
      latitude: 23.2979151,
      longitude: 112.973426,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '31栋',
        display: 'ALWAYS'
      }
    }, {
      id: 60,
      latitude: 23.297929,
      longitude: 112.9738767,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '32栋',
        display: 'ALWAYS'
      }
    }, {
      id: 61,
      latitude: 23.2981418,
      longitude: 112.97341007,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '33栋',
        display: 'ALWAYS'
      }
    }, {
      id: 62,
      latitude: 23.2983585,
      longitude: 112.9733886,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '34栋',
        display: 'ALWAYS'
      }
    }, {
      id: 63,
      latitude: 23.296836,
      longitude: 112.9771490,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '35栋',
        display: 'ALWAYS'
      }
    }, {
      id: 64,
      latitude: 23.2965996,
      longitude: 112.9774441,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '36栋',
        display: 'ALWAYS'
      }
    }, {
      id: 65,
      latitude: 23.2968460,
      longitude: 112.9775567,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '37栋',
        display: 'ALWAYS'
      }
    }, {
      id: 66,
      latitude: 23.297038,
      longitude: 112.9777069,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '38栋',
        display: 'ALWAYS'
      }
    }, {
      id: 67,
      latitude: 23.2973091,
      longitude: 112.97763723,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '39栋',
        display: 'ALWAYS'
      }
    }, {
      id: 68,
      latitude: 23.297309,
      longitude: 112.978093,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '40栋',
        display: 'ALWAYS'
      }
    },{
      id: 69,
      latitude: 23.296841,
      longitude: 112.978050,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '41栋',
        display: 'ALWAYS'
      }
    },{
      id: 70,
      latitude: 23.2972943,
      longitude: 112.97470289,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '国际学院公寓',
        display: 'ALWAYS'
      }
    },{
      id: 71,
      latitude: 23.2972943,
      longitude: 112.97470289,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '国际学院公寓',
        display: 'ALWAYS'
      }
    },{
      id: 72,
      latitude: 23.29559452,
      longitude: 112.97615665,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '1栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 73,
      latitude: 23.295855,
      longitude: 112.97615,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '2栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 74,
      latitude: 23.2961562,
      longitude: 112.976156653,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '3栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 75,
      latitude: 23.2965848,
      longitude: 112.9763926,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '4栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 76,
      latitude: 23.295609,
      longitude: 112.975915254,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '5栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 77,
      latitude: 23.295865,
      longitude: 112.975931,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '6栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 78,
      latitude: 23.295604,
      longitude: 112.97568,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '7栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 79,
      latitude: 23.2958507,
      longitude: 112.975668,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '8栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 80,
      latitude: 23.297348,
      longitude: 112.975920,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '9栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 81,
      latitude: 23.297348,
      longitude: 112.9763926,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '10栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 82,
      latitude: 23.29709235,
      longitude: 112.976446,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '11栋教师公寓',
        display: 'ALWAYS'
      }
    },{
      id: 83,
      latitude: 23.2972106,
      longitude: 112.9752554,
      iconPath: "/img/sushe.png",
      width: 30,
      height: 32,
      callout: {
        content: '国际楼',
        display: 'ALWAYS'
      }
    },{
      id: 84,
      latitude: 23.300245,
      longitude: 112.97216016,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '紫荆园',
        display: 'ALWAYS'
      }
    },{
      id: 85,
      latitude: 23.30264500,
      longitude: 112.9697139,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '桃李园',
        display: 'ALWAYS'
      }
    },{
      id: 86,
      latitude: 23.30501479,
      longitude: 112.9671551,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '快递站',
        display: 'ALWAYS'
      }
    },{
      id: 87,
      latitude: 23.30089,
      longitude: 112.9748209,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '大巴乘车点',
        display: 'ALWAYS'
      }
    },{
      id: 87,
      latitude: 23.30089,
      longitude: 112.9748209,
      iconPath: "/img/others.png",
      width: 30,
      height: 32,
      callout: {
        content: '杉叶',
        display: 'ALWAYS'
      }
    },
    
  ],
    distance: '',
    cost: '',
    polyline: [],
    userLongitude: 112.971672,
    userLatitude: 23.301231,
    inSchool: false,
    isLoading: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(e) {
    console.log(e)
    var _this = this

    if (e.markerId !== '' && Object.keys(e).length !== 0) {
      _this.makertap(e);
    }
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标  
      success: function(res) {
        _this.setData({
          // 获取用户经纬度
          userLongitude: res.longitude,
          userLatitude: res.latitude
        })
      }
    })
  },
  onReady: function() {
    var that = this;
    // 加载显示
    setTimeout(function() {
      that.setData({
        isLoading: false
      });
    }, 800);

  },

  // 点击标记点时触发
  makertap: function(e) {
    console.log(e)
    console.log("--------------")
    var id = e.markerId;
    var that = this;
    const markers = that.data.markers;
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标  
      success: function(res) {
        that.setData({
          userLongitude: res.longitude,
          userLatitude: res.latitude
        });
        that.setData({
          activePlaceID: id,
          placeName: that.data.markers[id].callout.content
        })
        var userLocation = that.data.userLongitude + ',' + that.data.userLatitude;
        var destination = that.data.markers[id].longitude + ',' + that.data.markers[id].latitude;
        that.planPolyline(userLocation, destination);
      }
    })

  },
  planPolyline: function(origin, destination) {
    var that = this;
    var id = that.data.activePlaceID;
    //规划步行路线
    var myAmapFun = new amapFile.AMapWX({
      key: '9fc43bcb891e355a59bf7ae9819486f3'
    });
    myAmapFun.getWalkingRoute({
      origin: origin,
      destination: destination,
      success: function(data) {
        var points = [];
        if (data.paths && data.paths[0] && data.paths[0].steps) {
          var steps = data.paths[0].steps;
          for (var i = 0; i < steps.length; i++) {
            var poLen = steps[i].polyline.split(';');
            for (var j = 0; j < poLen.length; j++) {
              points.push({
                longitude: parseFloat(poLen[j].split(',')[0]),
                latitude: parseFloat(poLen[j].split(',')[1])
              })
            }
          }
        }
        that.setData({
          json: data.paths[0],
          polyline: [{
            points: points,
            color: "#7acfa6",
            width: 6
          }]
        });
        if (data.paths[0] && data.paths[0].distance) {
          that.setData({
            distance: data.paths[0].distance + '米'
          });
        }
        if (data.paths[0] && data.paths[0].duration) {
          that.setData({
            cost: parseInt(data.paths[0].duration / 60) + '分钟'
          });
        }
        var markers = that.data.markers;
        var points = that.data.polyline[0].points;
        //暂时一共88个坐标点
        markers[88] = {
          id: 88,
          latitude: points[0].latitude,
          longitude: points[0].longitude,
          iconPath: '../../img/mapicon_navi_s.png',
          width: 23,
          height: 33
        };
        markers[89] = {
          id: 89,
          latitude: points[points.length - 1].latitude,
          longitude: points[points.length - 1].longitude,
          iconPath: '../../img/mapicon_navi_e.png',
          width: 24,
          height: 34
        }

        that.setData({
          markers: markers,
        })
      },
    })
  },

  // location: function() {
  //   console.log("点击了")
  //   var _this = this
  //   wx.getLocation({
  //     type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标  
  //     success: function(res) {
  //       console.log(res)
  //       console.log("触发了")
  //       _this.setData({
  //         userLongitude: res.longitude,
  //         userLatitude: res.latitude
  //       })
  //     },
  //     fail: function (errInfo) {
  //       console.info(errInfo)
  //     }
  //   })
  // },


  // 定位到用户位置
  async location() {
    let self = this
    try {
      await this.getWxLocation()//等待
    } catch (error) {
      Model({
        title: '温馨提示',
        tip: '获取权限失败，需要获取您的地理位置才能为您提供更好的服务！是否授权获取地理位置？',
        showCancel: true,
        confirmText: '前往设置',
        cancelText: '取消',
        sureCall() {
          self.toSetting()
        },
        cancelCall() {}
      })
      return
    }
  },
  
  getWxLocation() {
    wx.showLoading({
      title: '定位中...',
      mask: true,
    })
    return new Promise((resolve, reject) => {
      let _locationChangeFn = (res) => {
        var that = this
        console.log('location change', res)
        that.setData({
          userLongitude: res.longitude,
          userLatitude: res.latitude
        })
        console.log(that.data.userLatitude,that.data.userLongitude)
        wx.hideLoading()
        wx.offLocationChange(_locationChangeFn)
      }
      wx.startLocationUpdate({
        success: (res) => {
          console.log(res);
          wx.onLocationChange(_locationChangeFn)
          resolve()
        },
        fail: (err) => {
          console.log('获取当前位置失败', err)
          wx.hideLoading()
          reject()
        }
      })
    })
  },
  toSetting() {
    let self = this
    wx.openSetting({
      success(res) {
        console.log(res)
        if (res.authSetting["scope.userLocation"]) {
          // res.authSetting["scope.userLocation"]为trueb表示用户已同意获得定位信息，此时调用getlocation可以拿到信息
          self.authorization()
        }
      }
    })
  },

  moveSchool: function() {
    //视图返回学校
    var _this = this;
    _this.setData({
      userLongitude: 112.971672,
      userLatitude: 23.301231,
    })
  },
  jtt: function() {
    wx.previewImage({
      current: 'https://pic1.zhimg.com/v2-86101014417ea17aebd6d2aab304f41d_r.jpg?source=1940ef5c', // 当前显示图片的http链接
      urls: ["https://pic1.zhimg.com/v2-86101014417ea17aebd6d2aab304f41d_r.jpg?source=1940ef5c"] // 需要预览的图片http链接列表
    })
  },
  goDetail: function() {
    var that = this;
    const latitude = that.data.markers[that.data.activePlaceID].latitude;
    const longitude = that.data.markers[that.data.activePlaceID].longitude;
    const name = that.data.markers[that.data.activePlaceID].callout.content;
    wx.openLocation({
      latitude,
      longitude,
      name,
      address: '广州工商学院(三水校区)',
      scale: 18
    })
  }
})